<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<md-dialog aria-label="Define dates for the subscription">
  <md-dialog-content layout-padding>
    <form name="SubscriptionForm" ng-submit="$event.preventDefault()">
      <h4>Accept subscription</h4>
      <div ng-cloak layout="column">
        <div class="md-inline-form">
          <md-input-container>
            <label>Start date</label>
            <md-datepicker ng-model="starting_at" md-min-date="now"></md-datepicker>
          </md-input-container>
          <md-input-container>
            <label>End date</label>
            <md-datepicker ng-model="ending_at" md-min-date="starting_at"></md-datepicker>
          </md-input-container>
        </div>
        <md-input-container>
          <div layout="column" ng-cloak class="md-inline-form">
            <h5>If needed, add a message:</h5>
            <textarea ng-model="reason" aria-label="Reason"></textarea>
          </div>
        </md-input-container>
        <div ng-if="canUseCustomApiKey">
          <h5 style="margin-bottom: 20px">This plan allows custom API keys. You can provide it here.</h5>
          <div>
            <api-key-validated-input
              form-reference="SubscriptionForm"
              api-id="apiId"
              application-id="applicationId"
              on-change="dialogSubscriptionAcceptController.onApiKeyValueChange"
            ></api-key-validated-input>
          </div>
        </div>
      </div>
    </form>
  </md-dialog-content>

  <md-dialog-actions layout="row">
    <md-button ng-click="dialogSubscriptionAcceptController.hide()">Cancel</md-button>
    <md-button
      class="md-raised md-primary"
      ng-click="dialogSubscriptionAcceptController.save()"
      ng-disabled="dialogSubscriptionAcceptController.customApiKeyInputState === 'invalid'
                            || SubscriptionForm.$invalid"
      >Accept</md-button
    >
  </md-dialog-actions>
</md-dialog>
